package model

import (
	"time"
)

const (
	OrderStatusPendingDelivery = "PENDING_DELIVERY" // 待派送
	OrderStatusInProgress      = "IN_PROGRESS"      // 派送中
	OrderStatusComplete        = "COMPLETED"        // 已完成
	OrderStatusCancelled       = "CANCELLED"        // 已取消
)

const (
	SourceManualEntry = "MANUAL_ENTRY" // 手动录入
)

type OrderModel struct {
	Id               int64     `json:"id" xorm:"pk autoincr comment('auto_increment') BIGINT(20)"`
	MerchantId       int64     `json:"merchant_id" xorm:"not null default 0 comment('门店ID') BIGINT(20)"`
	OrderNo          string    `json:"order_no" xorm:"not null default '' comment('订单号') VARCHAR(20)"`
	Status           string    `json:"status" xorm:"not null default '' comment('订单状态') VARCHAR(20)"`
	Source           string    `json:"source" xorm:"not null default '' comment('来源 MANUAL_ENTRY 手动录入') VARCHAR(20)"`
	OrderTotal       float64   `json:"order_total" xorm:"not null default 0.00 comment('订单总金额，币种：人民币') DECIMAL(13,2)"`
	Nickname         string    `json:"nickname" xorm:"not null default '' comment('客户昵称') VARCHAR(50)"`
	PhoneNumber      string    `json:"phone_number" xorm:"not null default '' comment('收件人号码') VARCHAR(20)"`
	Address          string    `json:"address" xorm:"not null default '' comment('地址') VARCHAR(128)"`
	DeliveryPersonId int64     `json:"delivery_person_id" xorm:"not null default 0 comment('派送员用户ID') BIGINT(20)"`
	CreateTime       time.Time `json:"create_time" xorm:"not null default '1980-01-01 00:00:00' comment('创建时间') TIMESTAMP"`
	LastUpdateTime   time.Time `json:"last_update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('最后更新时间') TIMESTAMP"`
}

func (*OrderModel) TableName() string {
	return "order"
}

type OrderItemNode struct {
	*OrderItemsModel `xorm:"extends"`
	ProductName      string `json:"product_name"`
}

type OrderNode struct {
	*OrderModel    `xorm:"extends"`
	DeliveryPerson string           `json:"delivery_person"`
	Products       []*OrderItemNode `json:"products"`
}
